import java.util.Scanner;
import java.util.Stack;

public class test6 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        System.out.println(isValid(str));
    }

    public static boolean isValid(String s) {
        if(s.length() % 2 !=0)
            return false;
        char[] chars = s.toCharArray();
        Stack<Character> stack = new Stack<>();
        for(char ch: chars){
            if(ch=='('||ch=='{'||ch=='[')
                stack.push(ch);
            else{
                if (stack.isEmpty()){
                    return false;
                }
                char flag = stack.peek();
                if((flag!='('&&ch==')')||(flag!='{'&&ch=='}')||(flag!='['&&ch==']'))
                    return false;
                stack.pop();
            }
        }
        if(!stack.isEmpty()){
            return false;
        }
        return true;
    }
}
